package com.housekeeping.housekeeping.administrator.adminsinformation.controller;

import com.housekeeping.housekeeping.administrator.adminsinformation.service.update.UpdateService;
import com.housekeeping.housekeeping.administrator.adminsinformation.service.update.UpdateServiceImpl;
import com.housekeeping.housekeeping.administrator.entity.AdminsInformation;
import com.housekeeping.housekeeping.administrator.utils.ResponseEntity;
import com.housekeeping.housekeeping.administrator.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/information/update")
public class UpdateController extends HttpServlet {
    private UpdateService service=new UpdateServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求字符集
        req.setCharacterEncoding("utf-8");
        //设置响应字符集
        resp.setContentType("text/html;charset=utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        AdminsInformation data = service.alter(id);
        ResponseEntity<AdminsInformation> entity=null;

        try {
            entity = ResponseEntity.success(data);
        }catch (Exception ex){
            entity=ResponseEntity.error(404,"系统繁忙");
        }
        ResponseUtils.responseJson(resp,entity);
    }
}
